﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ShenLan.Common
{
    /// <summary>
    /// 自定义时间操作类
    /// </summary>
    public class DateTimeHandler
    {
        /// <summary>
        /// 根据日期获取星期,dateTime:待输入日期,return:输入日期的星期几,如星期三
        /// </summary>
        /// <param name="dateTime">待输入日期</param>
        /// <returns>输入日期的星期几,如星期三</returns>
        public static string GetWeekdayByDate(DateTime dateTime)
        {
            string weekDay = "";
            try
            {
                var oDay = (Week)dateTime.DayOfWeek;
                switch (oDay)
                {
                    case Week.Monday:
                        weekDay = "星期一";
                        break;
                    case Week.Tuesday:
                        weekDay = "星期二";
                        break;
                    case Week.Wednesday:
                        weekDay = "星期三";
                        break;
                    case Week.Thursday:
                        weekDay = "星期四";
                        break;
                    case Week.Friday:
                        weekDay = "星期五";
                        break;
                    case Week.Saturday:
                        weekDay = "星期六";
                        break;
                    default:
                        weekDay = "星期天";
                        break;
                }
                return weekDay;
            }
            catch { return "获取星期出错"; }
        }

        /// <summary>
        /// 根据日期获取星期,dateTime:待输入string类型日期,return:输入日期的星期几,如星期三
        /// </summary>
        /// <param name="dateTime">待输入string类型日期</param>
        /// <returns>输入日期的星期几,如星期三</returns>
        public static string GetWeekdayByDate(string dateTime)
        {
            string weekDay = "";
            try
            {
                var oDay = Convert.ToDateTime(dateTime).DayOfWeek;
                switch (oDay)
                {
                    case DayOfWeek.Monday:
                        weekDay = "星期一";
                        break;
                    case DayOfWeek.Tuesday:
                        weekDay = "星期二";
                        break;
                    case DayOfWeek.Wednesday:
                        weekDay = "星期三";
                        break;
                    case DayOfWeek.Thursday:
                        weekDay = "星期四";
                        break;
                    case DayOfWeek.Friday:
                        weekDay = "星期五";
                        break;
                    case DayOfWeek.Saturday:
                        weekDay = "星期六";
                        break;
                    default:
                        weekDay = "星期天";
                        break;
                }
                return weekDay;
            }
            catch { return "获取星期出错"; }
        }



        /// <summary>
        /// 星期
        /// </summary>
        public enum Week
        {
            /// <summary>
            ///  表示星期日。
            /// </summary>
            Sunday = 0,

            /// <summary>
            /// 表示星期一。
            /// </summary>
            Monday = 1,

            /// <summary>
            /// 表示星期二。
            /// </summary>
            Tuesday = 2,

            /// <summary>
            /// 表示星期三。
            /// </summary>
            Wednesday = 3,

            /// <summary>
            /// 表示星期四。
            /// </summary>
            Thursday = 4,

            /// <summary>
            /// 表示星期五。
            /// </summary>
            Friday = 5,

            /// <summary>
            /// 表示星期六。
            /// </summary>
            Saturday = 6,
        }
    }
}